<? session_start(); ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
	<script type="text/javascript" src="http://ape-jsf.datacube.hu/Clients/JavaScript.js"></script>
	<script type="text/javascript" src="ape_config.js"></script>
	<script type="text/javascript" src="ape_adapter.js"></script>
</head>
<body>

APE server running.<br>
Welcome, "<?=session_id()?>" !<br>
Waiting for your messages, send them with &lt;enter&gt;.<br>
<br>
<textarea wrap="hard" style="width:400px;height:100px" id="apetunnel"></textarea><br>
<input disabled style="width:400px" onKeyPress="return disableEnterKey(event)" id="message1"></input>


<script type="text/javascript">

var ape=new ape_adapter({
	'client_name': '<?=session_id()?>',
	'onready': ape_onready,
	'onmessage': ape_onmessage
});

function ape_onready()
{
	$("#message1").attr("disabled",false);
	$("#message1").focus();
	//alert("ape_ready");
}

function ape_onmessage(raw)
{
	/* uzenet erkezett, hozzabasszuk #apetunnel-hez */
	val=$("#apetunnel").val();
	val+=(val==''?"":"\n")+"..."+raw.data.client_name.substring(raw.data.client_name.length-8)+": "+raw.data.message;
	$("#apetunnel").val(val);
	
	document.getElementById("apetunnel").scrollTop = document.getElementById("apetunnel").scrollHeight;
}

function send_message()
{
	var d=new Date;
	
	if((message=$("#message1").val())=='') return;
	params={
		'data': {
			'stamp': d.getTime(),
			'client_name': ape.client_name,
			'message': message
		}
	};
	$("#message1").val('');
	
	$.getJSON("ape_broadcast.php",params,
		function(resp)
		{
			$("#message1").focus();
		}
	);
}


function disableEnterKey(e)
{
    var key;

    if(window.event)
		key = window.event.keyCode;     //IE
	else
		key = e.which;     //firefox

	if(key == 13){
		send_message();
	}

}

</script>

</body>
</html>
